package com.bsoft.exchange;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.ValueFilter;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.bsoft.exchange.dao.his.AppointmentMapper;
import com.bsoft.exchange.dao.his.RegisterMapper;
import com.bsoft.exchange.dao.his.SystemConfigMapper;
import com.bsoft.exchange.dao.his.YBServiceMapper;
import com.bsoft.exchange.domain.*;
import com.bsoft.exchange.param.SignParam;
import com.bsoft.exchange.pojo.JsjlPojo;
import com.bsoft.exchange.pojo.ListAppointmentWaitPojo;
import com.bsoft.exchange.pojo.OutResponse;
import com.bsoft.exchange.service.ListAppointmentWaitService;
import com.bsoft.exchange.service.YBService;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.DateUtil;
import com.bsoft.exchange.util.IdentityManager;
import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@EnableSwagger2
@SpringBootApplication(scanBasePackages = { "com.bsoft.exchange","com.bsoft.exchange.util" },exclude = DataSourceAutoConfiguration.class)
@EnableScheduling
public class ExchangeFrameworkApplication extends SpringBootServletInitializer{

	@Bean
	public HttpMessageConverters fastJsonConfigure() {
		FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
		FastJsonConfig fastJsonConfig = new FastJsonConfig();
		fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat, SerializerFeature.WriteNullStringAsEmpty,
				SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty);

		// 日期格式化
		fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
		converter.setFastJsonConfig(fastJsonConfig);
		
		 fastJsonConfig.setSerializeFilters(new ValueFilter() {
	            @Override
	            public Object process(Object object, String name, Object value) {
	                if (value == null){
	                    return "";
	                }
	                if (value instanceof Date){
	                    return DateUtil.dateFormat((Date) value);
	                }

	                return value;
	            }
	        });
		 

		List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
		supportedMediaTypes.add(MediaType.ALL); // 全部格式
		converter.setSupportedMediaTypes(supportedMediaTypes);
	    
		return new HttpMessageConverters(converter);
	}

	public static void main(String[] args) {
		ConfigurableApplicationContext run = SpringApplication.run(ExchangeFrameworkApplication.class, args);
		SystemConfigMapper systemConfigMapper = run.getBean(SystemConfigMapper.class);
		String value = systemConfigMapper.getValueByConfigName(1L, "WECHAT_INVOICE_ACTIVATION");
		System.out.println(value);
//		List<HyxxDomain> sXh = bean.getSXh(1, "2185", DateUtil.StrToFormatDate("2020-12-21 00:00:00", "yyyy-MM-dd HH:mm:ss"), "13406", 1);
//		System.out.println(sXh);
	}
	
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(ExchangeFrameworkApplication.class);
	}
	
	

}
